package com.spboot.app.controller;

import cn.hutool.core.bean.BeanUtil;
import com.spboot.app.pojo.Baoming;
import com.spboot.app.service.BaomingService;
import com.spboot.app.service.SaishiService;
import com.spboot.app.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/baoming")
@Api(tags = { "报名控制器" })
public class BaomingController {

    @Autowired
    private BaomingService service;
    private SaishiService saishiService;

    @ApiOperation(value = "用户报名赛事", httpMethod = "POST")
    @RequestMapping("/insert")
    @ApiImplicitParam(name = "data", value = "使用json数据提交", type = "json", dataTypeClass = Baoming.class, paramType = "body")
    public R insert(@RequestBody Map data) {
        Baoming post = BeanUtil.mapToBean(data, Baoming.class, true);
        return service.insert(post, data);
    }

    @ApiOperation(value = "根据赛事ID获取报名选手列表", httpMethod = "GET")
    @RequestMapping("/getListBySaishiId")
    public R<List<Map<String, Object>>> getListBySaishiId(@RequestParam Integer saishi_id) {
        return service.getListBySaishiId(saishi_id);
    }

    @ApiOperation(value = "用户取消报名赛事", httpMethod = "POST")
    @RequestMapping("/delete")
    @ApiImplicitParam(name = "data", value = "使用json数据提交", type = "json", dataTypeClass = Baoming.class, paramType = "body")
    public R delete(@RequestBody Map data) {
        Baoming post = BeanUtil.mapToBean(data, Baoming.class, true);
        return service.delete(post, data);
    }


}
